from tools.convert import translate as t
from tools.convert import to_string as s


def assertTypes(name, value, types, *, prefix="参数"):
    if not isinstance(value, types):
        raise TypeError(t('%s: "%s"=`%s` 值无效 (类型只能是 %s)', t(prefix), name, value, s(types)))


def assertRange(name, value, values, *, prefix="参数"):
    if value not in values:
        raise ValueError(t('%s: "%s"=`%s` 值无效 (值只能是 %s)') % (t(prefix), name, value, s(values)))


def assertNotNone(name, value, *, prefix="参数"):
    if value is None:
        raise ValueError(t('%s: "%s" 不能为空') % (t(prefix), name))


def assertNotEmpty(name, value, *, prefix="参数"):
    if not value:
        raise ValueError(t('%s: "%s" 必须有值') % (t(prefix), name))


# 测试代码
if __name__ == "__main__":
    import os, tools.i18n

    os.chdir("../")
    tools.i18n.i18n_backstage('en_US', os.getcwd())

    print(assertRange("test", 1, (2, 3, 4)))
